﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.nickro.project.sound{
    import flash.media.*;
    import com.tobyfreeman.patterns.*;

    public class Sounds {

        private var pInstanceManager:InstanceManager;
        private var pGroupLookup:Object;
        var pMaxRetries:int;

        private static const MAX_RETRIES:int = 3;
        public static const LOAD_FAILED:String = "loadFailed";

        public function Sounds(id:String){
            super();
            pInstanceManager = new InstanceManager(this, id);
            pGroupLookup = new Object();
            pMaxRetries = MAX_RETRIES;
        }
        public function setMixerVolume(volume:Number):void{
            volume = Math.max(0, Math.min(volume, 1));
            var transform:SoundTransform = SoundMixer.soundTransform;
            transform.volume = volume;
            SoundMixer.soundTransform = transform;
        }
        public function loadSoundsFromXML(oXML:XML, groupName:String, folder:String=""):SoundsGroup{
            var oGroup:SoundsGroup = new SoundsGroup(groupName);
            oGroup.setExternalFolder(folder);
            oGroup.createFromXML(oXML);
            loadSoundGroup(oGroup);
            return (oGroup);
        }
        public function setMaxRetries(maxRetries:int):void{
            pMaxRetries = Math.max(1, maxRetries);
        }
        public function toString():String{
            return ((("[object Sounds id='" + pInstanceManager.id) + "']"));
        }
        public function getID():String{
            return (pInstanceManager.id);
        }
        public function loadSoundGroup(oGroup:SoundsGroup):String{
            pGroupLookup[oGroup.getName()] = oGroup;
            oGroup.startLoading(this);
            return (oGroup.getID());
        }
        public function getGroupWithName(name:String):SoundsGroup{
            return ((pGroupLookup[name] as SoundsGroup));
        }

        public static function getInstance(id:String):Sounds{
            return (Sounds(InstanceManager.getInstance(Sounds, id)));
        }

    }
}//package com.tobyfreeman.sound 
